<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="Pragma" content="no-cache">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
		<meta name="format-detection" content="telephone=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<title>会议室日程</title>
		<link rel="stylesheet" type="text/css" href="${base}/css/date.css" />
		<link rel="stylesheet" type="text/css" href="${base}/css/weui.min.css" />
		<script type="text/javascript">
			function stops() {
				return false;
			}
			document.oncontextmenu = stops;
		</script>
		<style type="text/css">
			html,
			body,
			.page {
				height: 100%
			}
			
			.weui-panel:before,
			.weui-panel:after {
				border: 0px;
			}
			
			#details:after {
				content: "";
				clear: both;
				display: table
			}
			
			{}
		</style>
	</head>

	<body>

		<div class="page" id="container">
			<div class="weui-tab">
				<div class="weui-tab__bd">
					<div class="wrapper02" id="demo06">
						<div class="scroller">
							<ul class="clearfix">

							</ul>
						</div>
					</div>
					<div id="details">
						<div class="left">
							<ul>
								<li>上午<br />(9:00~12:00)</li>
								<li>下午一<br />(14:00~18:00)</li>
							</ul>
						</div>
						<div class="right">
							<div class="room">
								<a href="room_details.html" style="color: #000;cursor: pointer;" id="room"></a>
							</div>
							<table cellspacing="" cellpadding="">
								<tr>
									<td id="morning"></td>
								</tr>
								<tr>
									<td id="afternoon"></td>
								</tr>
							</table>
						</div>
					</div>
					<div class="weui-flex" id="describe">
						<div class="weui-flex__item">
							<i></i>
							<span class="placeholder">已占有</span>
						</div>
						<div class="weui-flex__item">
							<i style="background: #EC8B89;"></i>
							<span class="placeholder">我相关的</span>
						</div>
					</div>
					<div class="weui-flex" style="position: absolute;bottom: 0;width: 100%;">
						<div class="weui-flex__item" id="create">
							<div class="placeholder">
								<a href="javascript:;" class="weui-btn weui-btn_primary">创建会议</a>
							</div>
						</div>
						<div class="weui-flex__item" id="more">
							<div class="placeholder">
								<a href="javascript:;" class="weui-btn weui-btn_default">更多</a>
							</div>
						</div>
					</div>
				</div>

				<div class="weui-tabbar">
				</div>
			</div>
		</div>
		<div class="page" id="room_build" style="background:  #EFEFF4;display: none;">
			<div class="weui-tab">
				<div class="weui-tab__bd">
					<div style="font-size:12px;color: #ADADAD;height: 30px;line-height: 30px;margin-left: 4%;">会议室信息</div>
					<div class="weui-cells weui-cells_form" style="margin-top: 0px;">
						<div class=weui-cell>
							<div class=weui-cell__hd><label class=weui-label>名称</label></div>
							<div class=weui-cell__bd> <input id="title" class=weui-input type=text required placeholder=输入会议室名称> </div>
							<div class=weui-cell__ft> <i class=weui-icon-warn></i> </div>
						</div>
						<div class=weui-cell>
							<div class=weui-cell__hd><label class=weui-label>备注</label></div>
							<div class=weui-cell__bd> <input id="content" class=weui-input type=text required placeholder=输入位置等信息> </div>
							<div class=weui-cell__ft> <i class=weui-icon-warn></i> </div>
						</div>
					</div>
					<div class="weui-cells__tips">修改该会议室信息</div>
					<div class="weui-btn-area">
						<a class="weui-btn weui-btn_primary" href="javascript:" onclick="roomcreate()">确定</a>
					</div>

				</div>

			</div>

		</div>
		<script src="${base}/js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/jquery-weui.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/flex.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/iscroll.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/navscroll.js" type="text/javascript" charset="utf-8"></script>
		<script src="${base}/js/date.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function parseURL(url) {
				if(url.indexOf("?") == -1) return
				var url = url.split("?")[1];
				var res = [];
				if(url.indexOf("&") == -1) {
					var arr = url.split("=");
					res[arr[0]] = arr[1]
				} else {
					var arr = url.split("&");
					for(var i = 0; i < arr.length; i++) {
						var key = arr[i].split("=");
						res[key[0]] = key[1]
					}
				}
				return res

			}
			var url2 = window.location.href;
			url2 = decodeURIComponent(url2)
			var res = parseURL(url2)
			$("#room").html(res.room)
			$("#title").val(res.room)
			var mdata = [];
			$.ajaxSettings.async = false;
			$.post("${base}/meet/orderByRoom", {
				room: res.room
			}, function(data) {
				mdata = data
			})
			$.ajaxSettings.async = false;
			var myDate = new Date();
			var date = myDate.getDate();
			program(date)

			function getnum(time) {
				var a = time.slice(0,10).split("-");
				return a[2]
			}

			function gethour(time) {
				var a = time.slice(11).split(":");
				return a[0]
			}
			$('.clearfix').on('click', 'li', function() {
				$("#afternoon,#morning").html("")
				$("#afternoon,#morning").removeClass("otherusing")
				$("#afternoon,#morning").removeClass("select")
				var date = $(this).attr("data-day");
				program(date)
			})

			function program(date) {
				console.log(mdata)
				if(mdata=="")return
				for(var i = 0; i < mdata.length; i++) {
					var num = getnum(mdata[i].starttime)
					if(num == date) {
						var html = "";
						html += '<div class="weui-panel">'
						html += '<div class="weui-panel__bd">'
						html += '<div class="weui-media-box weui-media-box_text">'
						html += '<h4 class="weui-media-box__title">' + mdata[i].topic + '</h4>'
						html += '<p class="weui-media-box__desc">' + mdata[i].bz + '</p>'
						html += '</div>'
						html += '</div>'
						html += '</div>'
						var hour1 = gethour(mdata[i].starttime);
						var hour2 = gethour(mdata[i].finishtime);
						if(hour1 < 12) {
							$("#morning").html(html)
							$("#morning").addClass("otherusing")

						} else {
							$("#afternoon").html(html)
							$("#afternoon").addClass("otherusing")

						}
						if(hour2 > 12) {
							$("#afternoon").html(html)
							$("#afternoon").addClass("otherusing")

						} else {
							$("#morning").html(html)
							$("#morning").addClass("otherusing")

						}
					}

				}
			}
			$(".right").on("click", "#afternoon,#morning", function() {
				if($(this).html() == "") {
					$(this).toggleClass("select")
				}
			})
			$("#create").click(function() {
				var myDate = new Date();
				var year = myDate.getFullYear()
				var month = myDate.getMonth() + 1;
				var date = $("li.cur").children().html()
				var starttime, finishtime;
				if($(".select").length > 1) {
					starttime = year + "-" + month + "-" + date + "T09:00";
					finishtime = year + "-" + month + "-" + date + "T18:00";
				} else {
					var type = $(".select").attr("id")
					if(type == "morning") {
						starttime = year + "-" + month + "-" + date + "T09:00";
						finishtime = year + "-" + month + "-" + date + "T12:00";
					} else {
						starttime = year + "-" + month + "-" + date + "T14:00";
						finishtime = year + "-" + month + "-" + date + "T18:00";
					}
				}
				var room = $("#room").html()
				var href = "${base}/meet/ordernav?room=" + room
				location.href = href;
			})
			$("#more").click(function() {
				$.actions({
					actions: [{
						text: "编辑会议室信息",
						className: "color-primary",
						onClick: function() {
							$("#container").hide() //do something
							$("#room_build").show()
						}
					}, {
						text: "删除该会议室",
						className: "color-warning",
						onClick: function() {
							$.confirm({
								title: '删除会议室',
								text: '确定删除？',
								onOK: function() {
									$(".weui-dialog").remove()
									$(".weui-mask").remove()
									$.post("${base}/meet/delete", { //删除会议室信息
										roomname: name,
										bz: content
									}, function(data) {
										if(data.res == "true") {
											alert("删除成功")
											history.go(-1)
										} else {
											alert("删除失败")
										}
									})
									
									//点击确认
								},
								onCancel: function() {
									$(".weui-dialog").remove()
									$(".weui-mask").remove()
								}
							});
						}
					}]
				});
				$(".weui-mask").remove()
			})

			function roomcreate() { //编辑会议室信息
				var name = $("#title").val();
				var content = $("#content").val();
				$.post("${base}/meet/edit", {//修改会议室信息
					roomname: name,
					bz: content
				}, function(data) {
					if(data.res == "true") {
						alert("修改成功")
						$("#room").html(name)
					} else {
						alert("修改失败")
					}
				})
				$("#container").show().siblings().hide()
			}
		</script>

	</body>

</html>